package io.github.wx.core.interceptor;

import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;
import com.jfinal.core.Controller;
import com.jfinal.kit.LogKit;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by jie on 2017/4/8.
 * 日志和统一异常处理
 */
public class LogAndExceptionInterceptor implements Interceptor {
    public void intercept(Invocation inv) {
        Controller controller = inv.getController();
        try {
            inv.invoke();
        } catch (Exception e) {
            Map<String, Object> result = new HashMap<String, Object>();
            result.put("result", Boolean.FALSE);
            result.put("msg", e.getClass().getName());
            controller.renderJson(result);
            LogKit.error("===========系统异常===========", e);
        } finally {
            //TODO 插入日志表
        }
    }
}
